package com.fourpigeon.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fourpigeon.utils.COSUtils;
import com.fourpigeon.utils.IdGenerator;
import com.fourpigeon.utils.LocalDateTimeSerializerUtils;
import com.qcloud.cos.http.HttpMethodName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * 博客评论
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@TableName("tb_blog_comments")
public class BlogComment {
    /**
     * 主键
     */
    @TableId(value = "id",type = IdType.AUTO)
    private Long id;
    /**
     * 用户id
     */
    private Long userId;
    /**
     * 用户名称
     */
    private String userName;
    /**
     * 用户头像
     */
    private String icon;
    /**
     * 父id
     */
    private Long blogId;
    /**
     * 楼层号
     */
    private Integer stage;
    /**
     * 回复内容
     */
    private String content;
    /**
     * 点赞数
     */
    private Integer likes = 0;
    /**
     * 是否点赞
     */
    private boolean isLike = false;
    /**
     * 状态码：0：正常，1：被举报，2：禁止查看
     */
    private Integer status = 0;
    /**
     * 创建时间
     */
    @JsonDeserialize(using = LocalDateTimeSerializerUtils.LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializerUtils.LocalDateTimeSerializer.class)
    private LocalDateTime createTime;
    /**
     * 更新时间
     */
    @JsonDeserialize(using = LocalDateTimeSerializerUtils.LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializerUtils.LocalDateTimeSerializer.class)
    private LocalDateTime updateTime;

    /**
     * 用户名称
     */
    private String iconUrl = "";

    public void set(long id,Long blogId,Integer stage, User user) {
        this.id = id;
        this.userId = user.getId();
        this.userName = user.getName();
        this.icon = user.getIcon();
        this.blogId = blogId;
        this.stage = stage;
        this.createTime = LocalDateTime.now();
        this.updateTime = LocalDateTime.now();
    }
    public void handlerImgs(){
        this.iconUrl = COSUtils.getSign(this.icon, HttpMethodName.GET);
    }
}
